home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
Dev
/
Oberon
/
source
/
OC
/
OC.mod
< prev
next >
Wrap
Text File
|
1995-06-29
|
10KB
|
387 lines
(*************************************************************************
$RCSfile: OC.mod $
Description: Main entry point for the Oberon-A compiler.
Created by: fjc (Frank Copeland)
$Revision: 5.22 $
$Author: fjc $
$Date: 1995/06/02 18:45:27 $
Copyright © 1993-1995, Frank Copeland
This module forms part of the OC program
See OC.doc for conditions of use and distribution
Log entries are at the end of the file.
*************************************************************************)
<* STANDARD- *>
MODULE OC;
IMPORT
SYS := SYSTEM, Kernel, Errors, e := Exec, ti := Timer, u := Utility,
d := Dos, du := DosUtil, Files, str := Strings, OCRev, OCStrings,
OCM, OCS, OCT, OCC, OCE, Compiler, wb := Workbench, i := Icon,
conv := Conversions, OCOut;
CONST
CopyrightStr = "Copyright © 1993-95 Frank Copeland\n";
VAR
startDir : d.FileLockPtr;
(* -- Command line template and parsing ------------------------------- *)
CONST
template =
"NS=NEWSYMFILE/S,BATCH/S,SETTINGS/K,FILES/M"
(* These are temporary and will disappear eventually *)
",FORCE/S";
template2 = "FILES/M";
helpStr =
"\nSETTINGS/K -- preferences file\n"
"FILES/M -- source file(s)\n"
"NS=NEWSYMFILE/S -- generate a new symbol file if necessary\n"
"BATCH/S -- batch compile\n"
"See OC.doc for more details\n\n"
"Arguments ? ";
TYPE
StringArray = POINTER [2] TO ARRAY MAX(INTEGER) OF e.LSTRPTR;
VAR
rdArgs, rdArgs2 : d.RDArgsPtr;
args : RECORD [2] (d.ArgsStruct)
newSymFile,
batch
: d.ArgBool;
settings
: d.ArgString;
files
: d.ArgStringArray;
force
: d.ArgBool;
END;
(* These are filled in by ParseArgs() *)
newSymFile, batch : BOOLEAN;
(*------------------------------------*)
PROCEDURE* Cleanup (VAR rc : LONGINT);
VAR oldDir : d.FileLockPtr;
BEGIN (* Cleanup *)
IF rdArgs # NIL THEN
d.FreeArgs (rdArgs);
d.FreeDosObject (d.rdArgs, rdArgs);
rdArgs := NIL
END;
IF rdArgs2 # NIL THEN
(* d.FreeArgs (rdArgs2); *)
d.FreeDosObject (d.rdArgs, rdArgs2);
rdArgs2 := NIL
END;
IF Kernel.fromWorkbench THEN oldDir := d.CurrentDir (startDir) END
END Cleanup;
(*------------------------------------*)
PROCEDURE Init ();
BEGIN (* Init *)
Kernel.SetCleanup (Cleanup);
rdArgs := d.AllocDosObjectTags (d.rdArgs, u.end);
rdArgs2 := d.AllocDosObjectTags (d.rdArgs, u.end);
ASSERT ((rdArgs # NIL) & (rdArgs2 # NIL));
rdArgs.extHelp := SYS.ADR (helpStr);
END Init;
(*------------------------------------*)
PROCEDURE CloneStr ( oldStr : e.LSTRPTR ) : e.LSTRPTR;
VAR newStr : e.LSTRPTR;
BEGIN (* CloneStr *)
SYS.NEW (newStr, str.Length (oldStr^) + 1);
COPY (oldStr^, newStr^);
RETURN newStr
END CloneStr;
(*------------------------------------*)
PROCEDURE ParseArgs ();
VAR
string : e.LSTRPTR; strings : StringArray;
i : INTEGER; ignore : BOOLEAN; ch : CHAR;
args2 : ARRAY 1 OF SYS.LONGWORD;
(*------------------------------------*)
PROCEDURE ParseString (s, msg : ARRAY OF CHAR);
VAR len : LONGINT; buffer : e.LSTRPTR;
<*$CopyArrays-*>
BEGIN (* ParseString *)
len := str.Length (s) + 2;
SYS.NEW (buffer, len);
COPY (s, buffer^);
buffer [len-2] := "\n"; buffer [len-1] := 0X;
rdArgs2.source.buffer := buffer;
rdArgs2.source.length := len - 1;
rdArgs2.source.curChr := 0;
rdArgs2.daList := 0; rdArgs2.buffer := NIL; rdArgs2.bufSiz := 0;
rdArgs2.extHelp := NIL; rdArgs2.flags := {};
args2 [0] := NIL;
IF d.OldReadArgs (template2, args2, rdArgs2) = NIL THEN
ignore := d.PrintFault (d.IoErr(), msg);
HALT (d.warn)
END
END ParseString;
BEGIN (* ParseArgs *)
newSymFile := (args.newSymFile = e.LTRUE);
batch := (args.batch = e.LTRUE);
IF args.settings = NIL THEN
ignore := OCM.LoadPrefs ("OC.prefs")
ELSE
IF ~OCM.LoadPrefs (args.settings^) THEN
OCOut.Str1 (OCStrings.OC1, args.settings^);
HALT (d.warn)
END
END;
IF OCM.SetNames # "" THEN
ParseString (OCM.SetNames, " !! SET");
strings := SYS.VAL (StringArray, args2 [0]);
IF strings # NIL THEN
i := 0;
WHILE strings [i] # NIL DO
OCS.Set (strings [i]^);
INC (i)
END;
END;
d.FreeArgs (rdArgs2)
END;
IF OCM.ClearNames # "" THEN
ParseString (OCM.ClearNames, " !! CLEAR");
strings := SYS.VAL (StringArray, args2 [0]);
IF strings # NIL THEN
i := 0;
WHILE strings [i] # NIL DO
OCS.Clear (strings [i]^);
INC (i)
END;
END;
d.FreeArgs (rdArgs2)
END;
OCC.OpenBuffers (OCM.CodeSize, OCM.ConstSize);
OCM.Force := (args.force = e.LTRUE);
END ParseArgs;
(*------------------------------------*)
PROCEDURE Main ();
(*------------------------------------*)
PROCEDURE Greetings;
BEGIN (* Greetings *)
OCOut.Str (OCRev.vString);
OCOut.Str (CopyrightStr);
OCOut.Str0 (OCStrings.OC13);
OCOut.Ln;
END Greetings;
(*------------------------------------*)
PROCEDURE WbArgs ();
VAR
wbStartup : wb.WBStartupPtr;
oldDir : d.FileLockPtr;
diskObj : wb.DiskObjectPtr;
toolTypes : wb.ToolTypePtr;
string : e.LSTRPTR;
arg : INTEGER;
codeSize,
constSize : LONGINT;
BEGIN (* WbArgs *)
ASSERT (i.base # NIL, 100);
wbStartup := SYS.VAL (wb.WBStartupPtr, Kernel.WBenchMsg);
(* Attempt to load the icon *)
startDir := d.CurrentDir (wbStartup.argList[0].lock);
diskObj := i.GetDiskObject (wbStartup.argList[0].name^);
IF diskObj # NIL THEN
toolTypes := diskObj.toolTypes;
string := i.FindToolType (toolTypes, "NEWSYMFILE");
IF string # NIL THEN args.newSymFile := e.LTRUE END;
string := i.FindToolType (toolTypes, "BATCH");
IF string # NIL THEN args.batch := e.LTRUE END;
string := i.FindToolType (toolTypes, "SETTINGS");
IF string # NIL THEN args.settings := CloneStr (string) END;
string := i.FindToolType (toolTypes, "FORCE");
IF string # NIL THEN args.force := e.LTRUE END;
i.FreeDiskObject (diskObj)
END;
ParseArgs();
Greetings;
IF wbStartup.numArgs = 1 THEN
Compiler.Interactive (newSymFile)
ELSE
FOR arg := 1 TO (wbStartup.numArgs - 1) DO
oldDir := d.CurrentDir (wbStartup.argList [arg].lock);
IF batch THEN
Compiler.Batch (wbStartup.argList [arg].name^, newSymFile)
ELSE
Compiler.Compile (wbStartup.argList [arg].name^, newSymFile)
END;
END
END
END WbArgs;
(*------------------------------------*)
PROCEDURE CliArgs ();
VAR ignore : BOOLEAN; i : INTEGER;
BEGIN (* CliArgs *)
IF d.ReadArgs (template, args, rdArgs) = NIL THEN
ignore := d.PrintFault (d.IoErr(), "ReadArgs");
HALT (d.warn)
END;
ParseArgs();
Greetings;
IF args.files = NIL THEN
Compiler.Interactive (newSymFile)
ELSE
i := 0;
WHILE args.files [i] # NIL DO
IF batch THEN Compiler.Batch (args.files [i]^, newSymFile)
ELSE Compiler.Compile (args.files [i]^, newSymFile)
END;
INC (i)
END;
END;
END CliArgs;
BEGIN (* Main *)
IF Kernel.fromWorkbench THEN WbArgs()
ELSE CliArgs()
END;
END Main;
<*$ClearVars+*>
BEGIN (* OC *)
ASSERT (e.SysBase.libNode.version >= 37);
Errors.Init;
Init();
Main();
IF Compiler.returnError THEN HALT (d.error)
ELSIF Compiler.returnWarn THEN HALT (d.warn)
END
END OC.
(***************************************************************************
$Log: OC.mod $
Revision 5.22 1995/06/02 18:45:27 fjc
- Greatly simplified command-line processing by deleting
arguments that overrode preferences settings.
Revision 5.22 1995/05/29 21:24:55 fjc
- Greatly simplified the command line arguments, removing
the options for over-riding preferences settings.
Revision 5.21 1995/05/19 16:07:23 fjc
- Uses module OCOut for console IO
Revision 5.20 1995/05/16 20:00:49 fjc
- Removed references to OCGUI.
Revision 5.19 1995/05/13 23:16:40 fjc
- Moved Compile(), Batch(), etc. to module Compiler.
Revision 5.18 1995/05/08 17:02:46 fjc
- Now opens the GUI for interactive control.
Revision 5.16 1995/04/02 13:59:56 fjc
- Added CODESIZE and CONSTSIZE arguments.
- Rewrote argument processing to use an ArgsStruct instead
of an array of LONGWORDs.
Revision 5.15 1995/02/27 17:14:10 fjc
- Added SMALLCODE, LARGECODE, SMALLDATA, LARGEDATA,
REGISTER and NOREGISTER command line arguments.
- Deleted TRACE command line argument.
Revision 5.14 1995/01/26 00:17:17 fjc
- Release 1.5
Revision 5.13 1995/01/16 10:38:22 fjc
- Fixed bug where an attempt was made to Lock (NIL,...),
causing an Enforcer hit.
Revision 5.12 1995/01/09 14:03:26 fjc
- Changed console output depending on OCM.Verbose.
- Removed command line arguments for icon names.
- Implemented Workbench arguments.
Revision 5.11 1995/01/05 11:43:08 fjc
- Changed Compiler.forceCode to OCM.Force.
- Added QUIET, NODEBUG and NOICONS arguments, and fixed
handling of VERBOSE, DEBUG and MAKEICONS.
Revision 5.10 1995/01/03 21:31:56 fjc
- Changed OCG to OCM.
- Changed to use catalogs:
- Uses OCM for console I/O instead of Out.
- Gets text from OCStrings instead of hard-coding it.
- Added support for preferences:
- Added preferences settings to command-line template.
- Added SETTINGS argument to load settings from a file.
Revision 5.8 1994/12/16 17:49:00 fjc
- Added command-line options to specify file extensions.
Revision 5.7 1994/11/13 11:44:09 fjc
- Fixed formatting of elapsed time reports.
Revision 5.6 1994/10/23 16:37:22 fjc
- Replaced StdIO with In and Out for console IO.
Revision 5.5 1994/09/25 18:17:32 fjc
- Changed CPOINTER declaration.
Revision 5.4 1994/09/19 23:10:05 fjc
- Re-implemented Amiga library calls
Revision 5.3 1994/09/16 18:13:12 fjc
- Now uses ReadArgs() to process arguments.
- Added SET and CLEAR arguments.
Revision 5.2 1994/09/15 10:46:34 fjc
- Replaced switches with pragmas.
- Used Kernel instead of SYSTEM.
- No longer uses IntuiUtil.
Revision 5.1 1994/09/03 19:29:08 fjc
- Bumped version number
***************************************************************************)